package com.gxa.finance.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.finance.pojo.Bill;
import com.gxa.finance.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@Component
@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    private BillService billService;

    /**
     * 创建收款计划
     * @param bill
     * @return
     */
    @PostMapping("/addBill")
    public R addBill(@RequestBody Bill bill){

        return billService.addBill(bill);

    }

    /**
     * 修改账单状态
     * @param bill
     * @return
     */
    @PostMapping("/updateBillStatus")
    public R updateBillStatus(@RequestBody Bill bill){
        return billService.updateBillStatus(bill);
    }

    /**
     * 分页查询全部收款计划
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/findBillList")
    public JsonResult findBillList(Integer currentPage, Integer pageSize,String b_type){

        return billService.findBillList(currentPage,pageSize,b_type);


    }

    /**
     * 根据状态分页查询全部
     * @param currentPage
     * @param pageSize
     * @param b_status 账单状态
     * @return
     */
    @GetMapping("/findByStatusBillList")
    public JsonResult findByStatusBillList(Integer currentPage, Integer pageSize,Integer b_status,String b_type){
        JsonResult jsonResult = new  JsonResult();
        QueryWrapper<Bill> queryWrapper = new QueryWrapper();
        queryWrapper.eq(b_status!=null,"b_status",b_status)
                    .eq(b_type!=null&&!b_type.isEmpty(),"b_type",b_type);
        Page<Bill> page = new Page<>(currentPage,pageSize);
        Page<Bill> billList = billService.page(page,queryWrapper);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        jsonResult.setData(billList.getRecords());
        jsonResult.setCount((int)billList.getTotal());
        return jsonResult;

    }

    /**
     * 查询时间段的收款计划
     * @param currentPage
     * @param pageSize
     * @param staTime
     * @param offTime
     * @return
     */
    @GetMapping("/findByDateBills")
    public JsonResult findByDateBills(Integer currentPage, Integer pageSize,String staTime,String offTime,String b_type,Integer b_status){

       return billService.findByDateBills(currentPage,pageSize,staTime,offTime,b_type,b_status);

    }

    /**
     * 根据订单id查询数据
     * @param orderId
     * @param b_type
     * @param b_status
     * @return
     */
    @GetMapping("/findByOrderId")
    public R findByOrderId(String orderId,String b_type, Integer b_status){
        return billService.findByOrderId(orderId,b_type,b_status);
    }

    /**
     * 根据账单id查询数据
     * @param billId
     * @param b_type
     * @param b_status
     * @return
     */
    @GetMapping("/findByBillId")
    public R findByBillId(String billId,String b_type, Integer b_status){
        return billService.findByBillId(billId,b_type,b_status);
    }


}
